﻿using ECommon.Dapper;
using ECommon.IO;
using ENode.Infrastructure;
using ENode.Messaging;
using ESTAR.Domain.Auth;
using ESTAR.Infrastructure;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace ESTAR.Denormalizers.Dapper
{
    public class UserInfoDenormalizer : AbstractDenormalizer, IMessageHandler<NewUserInfoRegisteredEvent>
    {
        public Task HandleAsync(NewUserInfoRegisteredEvent evnt)
        {
            return TryInsertRecordAsync(connection =>
            {
                return connection.InsertAsync(new
                {
                    Id = evnt.AggregateRootId,
                    UserName = evnt.UserName,
                    Password = evnt.Password,
                    CreatedOn = evnt.Timestamp,
                    UpdatedOn = evnt.Timestamp,
                    Version = evnt.Version
                }, Constants.UserTable);
            }, Constants.UserDbName);
        }
    }
}
